###############################################################################
# Makefile for the project USBKEY_STK525-series6-cdc
###############################################################################

## General Flags
PROJECT = USBKEY_STK525-series6-cdc
MCU = at90usb647
TARGET = USBKEY_STK525-series6-cdc.elf
CC = avr-gcc

CPP = avr-g++

## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)

## Compile options common for all C compilation units.
CFLAGS = $(COMMON)
CFLAGS += -Wall -gdwarf-2        -DF_CPU=16000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct
CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d 

## Assembly specific flags
ASMFLAGS = $(COMMON)
ASMFLAGS += $(CFLAGS)
ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2

## Linker flags
LDFLAGS = $(COMMON)
LDFLAGS += 


## Intel Hex file production flags
HEX_FLASH_FLAGS = -R .eeprom -R .fuse -R .lock -R .signature

HEX_EEPROM_FLAGS = -j .eeprom
HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings


## Include Directories
INCLUDES = -I"C:\Projects\Moussavi Project\Moussavi Embedded\Moussavi_1.7\Moussavi_1.7\USBKEY_STK525-series6-cdc-2_0_6-doc\at90usb128\demo\USBKEY_STK525-series6-cdc\gcc\..\conf" -I"C:\Projects\Moussavi Project\Moussavi Embedded\Moussavi_1.7\Moussavi_1.7\USBKEY_STK525-series6-cdc-2_0_6-doc\at90usb128\demo\USBKEY_STK525-series6-cdc\gcc\..\..\.." -I"C:\Projects\Moussavi Project\Moussavi Embedded\Moussavi_1.7\Moussavi_1.7\USBKEY_STK525-series6-cdc-2_0_6-doc\at90usb128\demo\USBKEY_STK525-series6-cdc\gcc\..\..\..\..\common" -I"C:\Projects\Moussavi Project\Moussavi Embedded\Moussavi_1.7\Moussavi_1.7\USBKEY_STK525-series6-cdc-2_0_6-doc\at90usb128\demo\USBKEY_STK525-series6-cdc\gcc\.." 

## Objects that must be built in order to link
OBJECTS = uart_usb_lib.o usb_descriptors.o usb_device_task.o usb_drv.o usb_specific_request.o usb_standard_request.o usb_task.o main.o power_drv.o stk_525.o uart_lib.o cdc_task.o scheduler.o 

## Objects explicitly added by the user
LINKONLYOBJECTS = 

## Build
all: $(TARGET) USBKEY_STK525-series6-cdc.hex USBKEY_STK525-series6-cdc.eep size

## Compile
uart_usb_lib.o: ../../uart_usb_lib.c
	$(CC) $(INCLUDES) $(CFLAGS) -c  $<

usb_descriptors.o: ../../usb_descriptors.c
	$(CC) $(INCLUDES) $(CFLAGS) -c  $<

usb_device_task.o: ../../../../modules/usb/device_chap9/usb_device_task.c
	$(CC) $(INCLUDES) $(CFLAGS) -c  $<

usb_drv.o: ../../../../lib_mcu/usb/usb_drv.c
	$(CC) $(INCLUDES) $(CFLAGS) -c  $<

usb_specific_request.o: ../../usb_specific_request.c
	$(CC) $(INCLUDES) $(CFLAGS) -c  $<

usb_standard_request.o: ../../../../modules/usb/device_chap9/usb_standard_request.c
	$(CC) $(INCLUDES) $(CFLAGS) -c  $<

usb_task.o: ../../../../modules/usb/usb_task.c
	$(CC) $(INCLUDES) $(CFLAGS) -c  $<

main.o: ../../main.c
	$(CC) $(INCLUDES) $(CFLAGS) -c  $<

power_drv.o: ../../../../lib_mcu/power/power_drv.c
	$(CC) $(INCLUDES) $(CFLAGS) -c  $<

stk_525.o: ../../../../lib_board/stk_525/stk_525.c
	$(CC) $(INCLUDES) $(CFLAGS) -c  $<

uart_lib.o: ../../../../../common/lib_mcu/uart/uart_lib.c
	$(CC) $(INCLUDES) $(CFLAGS) -c  $<

cdc_task.o: ../../cdc_task.c
	$(CC) $(INCLUDES) $(CFLAGS) -c  $<

scheduler.o: ../../../../../common/modules/scheduler/scheduler.c
	$(CC) $(INCLUDES) $(CFLAGS) -c  $<

##Link
$(TARGET): $(OBJECTS)
	 $(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET)

%.hex: $(TARGET)
	avr-objcopy -O ihex $(HEX_FLASH_FLAGS)  $< $@

%.eep: $(TARGET)
	-avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0

%.lss: $(TARGET)
	avr-objdump -h -S $< > $@

size: ${TARGET}
	@echo
	@avr-size -C --mcu=${MCU} ${TARGET}

## Clean target
.PHONY: clean
clean:
	-rm -rf $(OBJECTS) USBKEY_STK525-series6-cdc.elf dep/* USBKEY_STK525-series6-cdc.hex USBKEY_STK525-series6-cdc.eep

## Other dependencies
-include $(shell mkdir dep 2>NUL) $(wildcard dep/*)

